home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / fuelga.exe / MONITOR.BAS < prev    next >
BASIC Source File  |  1993-01-06  |  4KB  |  99 lines

  1. DECLARE FUNCTION DoMonitor% (Noww%, Top%, Mon%)
  2. '============================================================================
  3. '            Multiple Fuel Gauges with Cancel Button
  4. '            Aidan Coyne                    Jan 1993
  5. '            Compuserve ID :             100014,2700
  6. '============================================================================
  7. '
  8. ' To use MONITOR in your programs :
  9. ' 1. Make a call to SetUpMonitor() with required parameters
  10. ' 2. Continually make calls to DoMonitor() with the following parameters :
  11. '    Noww% : Current Position,  Top% : Maximum Position, 
  12. '    Mon% : Which Gauge to Update
  13. ' 3. When finished, make another call to SetUpMonitor with a row% value of 0
  14. '    This will cause the form to unload.
  15. '
  16. ' Note : You must know in advance the maximum value for the fuel gauge.
  17. ' e.g. if reading records from a file, maximum value would be the number
  18. ' of records to read.  Call could be made to DoMonitor after each read or
  19. ' after several reads.
  20. '
  21. ' You are free to use this code in your programs without obligation!
  22. ''============================================================================
  23. '
  24. '$FORM frmMonitor
  25. CONST FALSE = 0, TRUE = NOT FALSE
  26.  
  27. SUB CancelMonitor ()
  28. SHARED Cancelled% 'Shared with DoMonitor
  29. ' Called From frmMonitor.cmdCancel_Click()
  30. ' Simple set Cancelled% variable to be acted upon next time DoMonitor gets called
  31.  
  32.   Cancelled% = TRUE
  33.  
  34. END SUB
  35.  
  36. FUNCTION DoMonitor% (Noww%, Top%, Mon%)
  37. SHARED MonGraph$, Cancelled%
  38. ' Updates FUEL GAUGE monitor on screen
  39. ' Returns TRUE normally, FALSE if cancel button is pressed and confirmed
  40. ' Noww% - Current value
  41. ' top% - Max Value
  42. ' Mon% - Which monitor to update (1..3)
  43.  
  44. DoMonitor% = TRUE                                ' Assume cancel hasn't been pressed
  45. ThisGraph$ = MonGraph$
  46. IF Top% = 0 THEN EXIT FUNCTION                   ' Get out if not reasonable
  47. IF Noww% > Top% THEN EXIT FUNCTION               ' values
  48.  
  49. here! = (100 / Top%) * Noww%                     ' Work out what size string
  50. here% = (here! / 10) * 4                         ' to show in monitor label
  51. IF Noww% = Top% THEN here% = 42: BEEP
  52. grafik$ = STRING$(here%, CHR$(219))              ' Using chr$(219)( █ )
  53. MID$(ThisGraph$, 1) = grafik$
  54. frmMonitor.lblMonitor(Mon%).Caption = ThisGraph$ ' Now set the caption with the
  55.                                                  ' correct length string
  56. IF Cancelled% THEN DoMonitor% = FALSE            ' If cancel button pressed,
  57.                                                  ' then return FALSE
  58.  
  59. END FUNCTION
  60.  
  61. SUB SetUpMonitor (Row%, Col%, NumMons%, Title$(), CancelButton%)
  62. ' Row% & Col% determine where gauge goes on screen
  63. ' Row%=0        : Unloads gauge
  64. ' NumMons%      : Number of gauges on the form (1..3)
  65. ' Title$()      : Title Text for each gauge (Title$(0) is form caption)
  66. ' CancelButton% : Puts Cancel Button On Form if TRUE
  67.  
  68. SHARED MonGraph$, Cancelled%  'Shared with DoMonitor%()
  69.  
  70. IF Row% = 0 THEN
  71.   UNLOAD frmMonitor
  72.   EXIT SUB
  73. END IF
  74.  
  75. MonGraph$ = "  │   │   │   │   │   │   │   │   │   │   "
  76. Cancelled% = FALSE
  77. LOAD frmMonitor                                   ' Initialise Form
  78. frmMonitor.Top = Row%                             ' Set its coordinates
  79. frmMonitor.Left = Col%
  80. frmMonitor.Height = (NumMons% * 5) + 2            ' Set its height, width
  81. frmMonitor.Caption = Title$(0)                    ' and caption
  82.  
  83. IF CancelButton% THEN                             ' If cancel button required,
  84.   frmMonitor.Width = 57                           ' increase form width
  85. ELSE                                              ' otherwise disable cancel
  86.   frmMonitor.Width = 47                           ' button
  87.   frmMonitor.cmdCancel.Enabled = FALSE
  88. END IF
  89.  
  90. frmMonitor.SHOW
  91. FOR i% = 1 TO NumMons%
  92.   frmMonitor.frMonitor(i%).Visible = TRUE         ' Show each fuel gauge and
  93.   frmMonitor.lblMonitor(i%).Caption = MonGraph$   ' set each ones label
  94.   frmMonitor.lblMonTitle(i%).Caption = Title$(i%) ' and title
  95. NEXT
  96.  
  97. END SUB
  98.  
  99.